package com.jjmo.edu.info.manger.controller;

import com.jjmo.edu.info.manger.domain.Student;
import com.jjmo.edu.info.manger.service.StudentService;

import java.util.Scanner;

public class StudentController {


    public void start() {
        Scanner sc = new Scanner(System.in);

        studentLoop:
        while (true) {
            System.out.println("--------欢迎来到 <学生> 管理系统--------");
            System.out.println("请输入您的选择: 1.添加学生  2.删除学生  3.修改学生  4.查看学生  5.退出");
            String choice = sc.next();
            switch (choice) {
                case "1":
                    System.out.println("添加");
                    addStudent();
                    break;
                case "2":
                    System.out.println("删除");
                    break;
                case "3":
                    System.out.println("修改");
                    break;
                case "4":
                    System.out.println("查询");
                    break;
                case "5":
                    System.out.println("感谢您使用学生管理系统，再见！");
                    break studentLoop;

                default:
                    System.out.println("您的输入有误，请重新输入");
                    break;
            }
        }
    }

    public void addStudent() {
        StudentService studentService = new StudentService();
        Scanner sc = new Scanner(System.in);
        String id = "";
        while (true) {
            System.out.println("请输入学生ID");
            id = sc.next();
            boolean flag = studentService.isExists(id);
            if (flag) {
                System.out.println("学号已存在，请重新输入");

            } else {
                break;
            }
        }

        System.out.println("请输入学生姓名");
        String name = sc.next();
        System.out.println("请输入学生年龄");
        String age = sc.next();
        System.out.println("请输入学生生日");
        String birthday = sc.next();
        Student student = new Student(id, name, age, birthday);

        boolean result = studentService.addStudent(student);
        if (result) {
            System.out.println("添加成功");
        } else {
            System.out.println("添加失败");
        }
    }

    public void updateStudent() {
    }

    public void deleteStudent() {
    }

    public void findStudent() {
    }


}
